<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
	<head>
		<meta charset="utf-8">
		  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		  <title>学生主页</title>
	</head>
	<body>
      	<c:import url="stu_home.jsp"></c:import>
		<!-- 内容 -->
		<div class="layui-body container">
			<div class="row">
			<c:if test="${pageInfo==null}">
				${errorMsg}
			</c:if>
			<c:if test="${pageInfo.total eq 0}">
				<p style="margin-top: 200px;margin-left: 520px">暂无项目</p>
			</c:if>
			<c:if test="${pageInfo!=null}">
			
			<c:forEach items="${pageInfo.list}" var="taskProject">
			<div class="panel panel-default col-md-8 col-md-offset-2" style="margin-top: 75px">
			  <div class="panel-heading">
			    <h3 class="panel-title">
			    
			    	<strong>${taskProject.task.taskName}
			    	</strong>	
			    	<small>任务状态:<mark>
			    		<c:if test="${taskProject.task.taskStatus==0}">
			    		已删除
			    		</c:if>
			    		<c:if test="${taskProject.task.taskStatus==3}">
			    		已完成
			    		</c:if>
			    		<c:if test="${taskProject.task.taskStatus==2}">
			    		未完成
			    		</c:if>
			    	</mark></small>
			    </h3>
			  </div>
			  <div class="panel-body">
			  <form class="form-horizontal">
			  
				<fieldset>
				    <legend>项目信息</legend>
				    
				    	<div class="form-group">
							<label class="col-sm-3 control-label">项目名称:</label>
							<div class="col-sm-9">
								<p class="form-control-static">
								${taskProject.project.projectName}</p>
							</div>
							<input type="hidden" id="projectId" value="${taskProject.project.projectId}">
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">项目组长:</label>
							<div class="col-sm-2">
								<p class="form-control-static">
								${taskProject.group.leaderName }</p>
							</div>
							<label class="col-sm-3 control-label">团队名称:</label>
							<div class="col-sm-3">
								<p class="form-control-static">
								${taskProject.group.groupName }</p>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">项目简介:</label>
							<div class="col-sm-9">
								<p class="form-control-static">
									${taskProject.project.projectInfo}
								</p>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">预计完成时间:</label>
							<div class="col-sm-9">
								<p class="form-control-static">
									<c:if test="${taskProject.project.update_finishTime==null}">
										
										<fmt:formatDate value="${taskProject.project.finishTime}" pattern="yyyy-MM-dd"/>
									</c:if>
									<c:if test="${taskProject.project.update_finishTime!=null}">
										
										<fmt:formatDate value="${taskProject.project.update_finishTime}" pattern="yyyy-MM-dd"/>
									</c:if>
								</p>
							</div>
						</div>
				    
				  </fieldset>
				  
				  <fieldset>
				    <legend>任务信息</legend>
				    
				    	<div class="form-group">
							<label class="col-sm-3 control-label">任务名称:</label>
							<div class="col-sm-4">
								<p class="form-control-static">
								${taskProject.task.taskName}</p>
							</div>
							<input type="hidden" id="taskId" value="${taskProject.task.taskId}">
							<label class="col-sm-2 control-label">任务说明书:
							</label>
							<div class="col-sm-2">
								<p class="form-control-static">	<a href="${pageContext.request.contextPath}/file/downloadProjectFile.do?fileId=${taskProject.task.taskFile}">下载</a>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">gitee代码分支:</label>
							<div class="col-sm-9">
								<p class="form-control-static">
								<c:if test="${taskProject.task.branch==null}">
									 未设置
								</c:if>
								<c:if test="${taskProject.task.branch!=null}">
									${taskProject.task.branch}
									<input type="hidden" value="${taskProject.task.branch}" id="task_banch">
								</c:if>
								</p>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">任务介绍:</label>
							<div class="col-sm-9">
								<p class="form-control-static">
									${taskProject.task.task_introduction}
								</p>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">任务进度:</label>
							<div class="col-sm-9">
								<div class="progress" style="margin-top: 8px">
								  <div id="task_process" class="progress-bar" role="progressbar" aria-valuenow="${taskProject.task.process}" aria-valuemin="0" aria-valuemax="100" style="width: ${taskProject.task.process}%;">
								    ${taskProject.task.process}%
								  </div> 
								</div>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-3 col-md-offset-3">
							<button type="button" class="btn btn-success" id="btn_taskProcess">完成10%</button>
							</div>
						</div>
				  </fieldset>			  
				</form>
			  </div>
			  
			</div>
			</c:forEach>
			</c:if>
			</div>
			<div class="row">
				<div class="row col-sm-7 col-md-offset-5">
					共${pageInfo.total}条任务记录
				</div>
				<c:if test="${pageInfo.total ne 0}">
				<nav aria-label="Page navigation" class="col-sm-8 col-md-offset-2">
				  <ul class="pager">
				    <li class="previous"><a href="${pageContext.request.contextPath}/student/home.do?pageNum=${pageInfo.pageNum-1}"><span aria-hidden="true">&larr;</span> Older</a></li>
				    <li class="next"><a href="${pageContext.request.contextPath}/student/home.do?pageNum=${pageInfo.pageNum+1}">Newer <span aria-hidden="true">&rarr;</span></a></li>
				  </ul>
				</nav>
				</c:if>

			</div>
			
		</div>
<script>

$("#btn_taskProcess").click(function(){
	layer.confirm('是否更新任务进度？',{
		  btn: ['确定','取消'], //按钮
		  icon:3,
		}, function(){
		  var task_banch=$("#task_banch").val();
		  if(task_banch==null){
			  layer.msg('未设置gitee项目分支,请联系项目组长分配gitee项目分支',{icon:0});
			  return;
		  }
		  var num=Number($("#task_process").attr("aria-valuenow"))+10;
			if(num>100){
				layer.msg('已经达到100%',{icon:0});
				return;
			}
			var projectId=$("#projectId").val();
			var taskId=$("#taskId").val();
			console.log("更新任务进度:projectId-"+projectId+",taskId-"+taskId);
			$.ajax({
				url:"${pageContext.request.contextPath}/student/update_taskProcess.do",
				type:"GET",
				data:{"taskId":taskId,"projectId":projectId},
				success:function(result){
					console.log(result);
					if(result.code==100){
						$("#task_process").empty();
						$("#task_process").width(num+"%").attr("aria-valuenow",num).append(num+"%");
						layer.msg('任务进度更新成功', {icon: 1});
					}else{
						layer.msg('任务进度更新失败,'+result.extend.errorMsg, {icon: 5});
					}
				}
			});
			
		}, function(){
		  layer.msg('已取消', {icon: 2},{
		    time: 500, //20s后自动关闭
		  });
		}
	);

});

</script>
	</body>
</html>

